package com.custom.base.drawable

import android.graphics.Color
import android.graphics.drawable.Drawable
import com.custom.base.drawable.SDDrawable.Companion.getStateListDrawable

/**
 * 作者：
 * 时间：2021/1/14
 * 描述：SDDrawableManager
 */
class SDDrawableManager {
    private var mColorMain = 0
    private var mColorStroke = 0
    private var mColorMainPress = 0
    private var mColorGrayPress = 0
    private var mCorner = 0f
    private var mStrokeWidth = 0

    // -------------------------------mainColor
    fun getLayerMainColor(corner: Boolean): Drawable {
        val drawable = SDDrawable()
        drawable.color(getmColorMain()).strokeColor(getmColorMain()).strokeWidthAll(getmStrokeWidth())
        if (corner) {
            drawable.cornerAll(getmCorner())
        }
        return drawable
    }

    // --------------------------------white
    fun getLayerWhiteStrokeItemSingle(corner: Boolean): Drawable {
        val drawable = SDDrawable()
        drawable.strokeColor(getmColorStroke()).strokeWidthAll(getmStrokeWidth())
        if (corner) {
            drawable.cornerAll(getmCorner())
        }
        return drawable
    }

    fun getLayerWhiteStrokeItemTop(corner: Boolean): Drawable {
        val drawable = SDDrawable()
        drawable.strokeColor(getmColorStroke()).strokeWidth(getmStrokeWidth(), getmStrokeWidth(), getmStrokeWidth(), 0)
        if (corner) {
            drawable.corner(getmCorner(), getmCorner(), 0f, 0f)
        }
        return drawable
    }

    val layerWhiteStrokeItemMiddle: Drawable
        get() {
            val drawable = SDDrawable()
            drawable.strokeColor(getmColorStroke())
                .strokeWidth(getmStrokeWidth(), getmStrokeWidth(), getmStrokeWidth(), 0)
            return drawable
        }

    fun getLayerWhiteStrokeItemBottom(corner: Boolean): Drawable {
        val drawable = SDDrawable()
        drawable.strokeColor(getmColorStroke()).strokeWidthAll(getmStrokeWidth())
        if (corner) {
            drawable.corner(0f, 0f, getmCorner(), getmCorner())
        }
        return drawable
    }

    // --------------------------mainColorPress
    fun getLayerMainColorPress(corner: Boolean): Drawable {
        val drawable = SDDrawable()
        drawable.color(getmColorMainPress()).strokeColor(getmColorMainPress()).strokeWidthAll(getmStrokeWidth())
        if (corner) {
            drawable.cornerAll(getmCorner())
        }
        return drawable
    }

    // ---------------------------------gray
    fun getLayerGrayStrokeItemSingle(corner: Boolean): Drawable {
        val drawable = getLayerWhiteStrokeItemSingle(corner) as SDDrawable
        drawable.color(getmColorGrayPress())
        return drawable
    }

    fun getLayerGrayStrokeItemTop(corner: Boolean): Drawable {
        val drawable = getLayerWhiteStrokeItemTop(corner) as SDDrawable
        drawable.color(getmColorGrayPress())
        return drawable
    }

    val layerGrayStrokeItemMiddle: Drawable
        get() {
            val drawable = layerWhiteStrokeItemMiddle as SDDrawable
            drawable.color(getmColorGrayPress())
            return drawable
        }

    fun getLayerGrayStrokeItemBottom(corner: Boolean): Drawable {
        val drawable = getLayerWhiteStrokeItemBottom(corner) as SDDrawable
        drawable.color(getmColorGrayPress())
        return drawable
    }

    // ----------------------------selector
    fun getSelectorWhiteGray(corner: Boolean): Drawable {
        val white = SDDrawable()
        if (corner) {
            white.cornerAll(getmCorner())
        }
        val gray = SDDrawable()
        gray.color(getmColorGrayPress())
        if (corner) {
            gray.cornerAll(getmCorner())
        }
        return getStateListDrawable(white, null, null, gray)
    }

    fun getSelectorMainColor(corner: Boolean): Drawable {
        return getStateListDrawable(getLayerMainColor(corner), null, null, getLayerMainColorPress(corner))
    }

    fun getSelectorWhiteGrayStrokeItemSingle(corner: Boolean): Drawable {
        return getStateListDrawable(
            getLayerWhiteStrokeItemSingle(corner), null, null,
            getLayerGrayStrokeItemSingle(corner)
        )
    }

    fun getSelectorWhiteGrayStrokeItemTop(corner: Boolean): Drawable {
        return getStateListDrawable(
            getLayerWhiteStrokeItemTop(corner), null, null,
            getLayerGrayStrokeItemTop(corner)
        )
    }

    val selectorWhiteGrayStrokeItemMiddle: Drawable
        get() = getStateListDrawable(layerWhiteStrokeItemMiddle, null, null, layerGrayStrokeItemMiddle)

    fun getSelectorWhiteGrayStrokeItemBottom(corner: Boolean): Drawable {
        return getStateListDrawable(
            getLayerWhiteStrokeItemBottom(corner), null, null,
            getLayerGrayStrokeItemBottom(corner)
        )
    }

    // ----------------------getter setter-----------------------
    fun getmColorMain(): Int {
        return mColorMain
    }

    fun getmStrokeWidth(): Int {
        return mStrokeWidth
    }

    fun setmStrokeWidth(mStrokeWidth: Int) {
        this.mStrokeWidth = mStrokeWidth
    }

    fun getmCorner(): Float {
        return mCorner
    }

    fun setmCorner(mCorner: Float) {
        this.mCorner = mCorner
    }

    fun setmColorMain(mColorMain: Int) {
        this.mColorMain = mColorMain
    }

    fun getmColorStroke(): Int {
        return mColorStroke
    }

    fun setmColorStroke(mColorStroke: Int) {
        this.mColorStroke = mColorStroke
    }

    fun getmColorMainPress(): Int {
        return mColorMainPress
    }

    fun setmColorMainPress(mColorMainPress: Int) {
        this.mColorMainPress = mColorMainPress
    }

    fun getmColorGrayPress(): Int {
        return mColorGrayPress
    }

    fun setmColorGrayPress(mColorGrayPress: Int) {
        this.mColorGrayPress = mColorGrayPress
    }

    init {
        setmColorMain(Color.parseColor("#FC7507"))
        setmColorMainPress(Color.parseColor("#FFCC66"))
        setmColorStroke(Color.parseColor("#E5E5E5"))
        setmColorGrayPress(Color.parseColor("#E5E5E5"))
        setmCorner(10f)
        setmStrokeWidth(1)
    }
}